old_player_count = 0
new_player_count = 0
hunt_with_half = 0
dead_person = 0
defection = 0
my_reputation = 0
average_reputation = 1.0
round = 0
total_defection = 0
hunts = 0.0

def mean(numberList):
    if len(numberList) == 0:
        return float('nan')
 
    floatNums = [float(x) for x in numberList]
    return sum(floatNums) / len(numberList)

def hunt_choices(round_number, current_food, current_reputation, m, player_reputations):
	global total_defection
	global dead_person
	global hunt_with_half
	global defection
	global my_reputation
	global average_reputation
	global round
	global hunts
	round = round_number
	my_reputation = current_reputation
	average_reputation = mean(player_reputations)
	defections = defection
	hunt_decisions=list()
	hunts = 0.0
	for reputation in player_reputations:
		if total_defection == 0:
			if reputation >= current_reputation:
				if defections > 0:
					hunt_decisions.append('s')
					defections -= 1
				else:
					hunt_decisions.append('h')
					hunts += 1.0
			else:
				hunt_decisions.append('s')
		else:
			hunt_decisions.append('s')
	return hunt_decisions

def hunt_outcomes(food_earnings):
	global round
	global old_player_count
	global new_player_count
	global total_defection
	old_player_count = new_player_count
	new_player_count = len(food_earnings)
	if round > 1 and old_player_count > new_player_count:
		total_defection = 1

def round_end(award, m, number_hunters):
	global new_player_count
	global hunts
	global defection
	global my_reputation
	global average_reputation
	if float(number_hunters/float(new_player_count)) < float(hunts) or average_reputation < my_reputation:
		defection += 1
	else:
		defection -= 1
    

